package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppArticle;
import com.ruoyi.app.domain.AppArticleMine;
import com.ruoyi.app.service.AppArticleMineService;
import com.ruoyi.app.service.AppArticleService;
import com.ruoyi.cms.domain.Category;
import com.ruoyi.cms.domain.Comment;
import com.ruoyi.cms.service.ICategoryService;
import com.ruoyi.cms.service.ICommentService;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.BusinessException;
import com.ruoyi.framework.shiro.service.SysPasswordService;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.ISysNoticeService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/app/")
public class RegController extends BaseController {

    @Autowired
    private ISysUserService userService;

    @Autowired
    private SysPasswordService passwordService;

    //注册页面
    @RequestMapping("reg")
    public String goReg() {
        return "reg";
    }


    @PostMapping("/register")
    @ResponseBody
    public AjaxResult register(SysUser user) {
        if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(user))) {
            return error("新增用户'" + user.getLoginName() + "'手机号码已存在");
        }
        user.setSalt(ShiroUtils.randomSalt());
        user.setPassword(passwordService.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
        user.setCreateBy("ry");
        return toAjax(userService.insertUser(user));
    }


}
